image: docker:24.0.5
services:
  - docker:24.0.5-dind

variables:

stages:
  - build
  - upload
  - deploy

build:
  tags:
      - only-test
  stage: build
  before_script:
  - apt install -y python3 python3-pip python3-dev git
  script:
    - docker --version
    - docker build -t django_helloworld:$CI_COMMIT_SHORT_SHA .
  artifacts:
    paths:
      - /var/lib/docker

upload:
  image: "registry.gitlab.com/gitlab-org/cluster-integration/auto-deploy-image"
  tags:
      - only-test
  stage: upload
  before_script:
    - ./install_kuber.sh
  script:
    - kind load docker-image django_helloworld:${CI_COMMIT_SHORT_SHA}

deploy:
  image: "registry.gitlab.com/gitlab-org/cluster-integration/auto-deploy-image"
  tags:
      - only-test
  stage: deploy
  environment:
    name: production
  before_script:
    - kubectl version --client
    - kind delete clusters --all
    - kind create cluster --config configs/cluster_conf.yml
    - sleep 2s
    - kubectl apply -f configs/nginx_pod.yml
    - kind load docker-image django_helloworld:${CI_COMMIT_SHORT_SHA}
  script:
    - kubectl get pods
